Skip to content

fix: add C# references outside conditional ItemGroups - #770

Open
pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-conditional-itemgroup
Open

pcbeingused333 wants to merge 1 commit into
QuantConnect:masterfrom
pcbeingused333:fix/csproj-conditional-itemgroup

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Fixes #767

Root cause: lean library add appends a ProjectReference or PackageReference to ItemGroup[last()] and never reads Condition. When the last group is limited to Debug, the command still succeeds and records the library, but Release builds cannot resolve the new type.

Fix: both writers take the same group: the last direct ItemGroup of the project that has no Condition. If every group is conditional, or there is none, a new ItemGroup is added on the project element. Groups nested in a Target are left alone. An existing reference is still not duplicated.

Test: a project whose last or only ItemGroup is Condition="'$(Configuration)' == 'Debug'" used to receive the new reference inside that group. test_add_csharp_project_to_csproj_does_not_use_a_conditional_item_group, test_add_csharp_project_to_csproj_with_only_a_conditional_item_group_adds_an_unconditional_one, and test_add_csharp_package_to_csproj_does_not_use_a_conditional_item_group cover that for project and package references. A fourth test checks that an ItemGroup inside a Target is not used when the project already has an unconditional group.

This change was prepared with AI assistance.

lean library add appended the reference to the last ItemGroup. A Condition
on that group made the library available only in that configuration.
Project and package references now use a project ItemGroup with no
Condition, or a new one when every group is conditional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a C# library can silently restrict its reference to Debug builds

1 participant